home *** CD-ROM | disk | FTP | other *** search
/ 3D Games - Real-time Rend…ng & Software Technology / 3D Games - Real-time Rendering & Software Technology.iso / flysdk / plugin / weapon / hitmark.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-10  |  2.0 KB  |  121 lines

  1. #include "..\..\lib\Fly3D.h"
  2. #include "weapon.h"
  3.  
  4. int hitmark::step(int dt)
  5. {
  6.     if (node==0)
  7.         life=-1;
  8.     else
  9.     {
  10.     life-=dt;
  11.     if (mode)
  12.         {
  13.         pos.z+=vel.z*dt;
  14.         return 1;
  15.         }
  16.     }
  17.     return 0;
  18. }
  19.  
  20. void hitmark::draw()
  21. {
  22.     if (texture==-1 || node==0)
  23.         return;
  24.     tc->use(texture);
  25.  
  26.     float transp;
  27.     if (life<fadetime)
  28.         if (life>=0)
  29.             transp=(float)life/fadetime;
  30.         else transp=0.0f; 
  31.     else transp=1.0f;
  32.  
  33.     glDepthMask(GL_FALSE);
  34.  
  35.     if (flyengine->piclib[texture]->bytespixel!=4)
  36.     {
  37.         glBlendFunc(GL_ZERO,GL_ONE_MINUS_SRC_COLOR);
  38.         glColor3f(transp,transp,transp);
  39.     }
  40.     else
  41.     {
  42.         glColor4f(node->color.x+dynlight.x,node->color.y+dynlight.y,node->color.z+dynlight.z,transp);
  43.         dynlight.null();
  44.     }
  45.  
  46.     static vector x,y;
  47.     if (mode)
  48.     {
  49.         x=flyengine->cam->X*size;
  50.         y=flyengine->cam->Y*size;
  51.     }
  52.     else 
  53.     {
  54.         x=X*size;
  55.         y=Y*size;
  56.     }
  57.  
  58.     glBegin(GL_QUADS);
  59.  
  60.     glTexCoord2f(1,0);
  61.     glVertex3f(pos.x+x.x-y.x, pos.y+x.y-y.y, pos.z+x.z-y.z);
  62.  
  63.     glTexCoord2f(1,1);
  64.     glVertex3f(pos.x+x.x+y.x, pos.y+x.y+y.y, pos.z+x.z+y.z);
  65.  
  66.     glTexCoord2f(0,1);
  67.     glVertex3f(pos.x+y.x-x.x, pos.y+y.y-x.y, pos.z+y.z-x.z);
  68.  
  69.     glTexCoord2f(0,0);
  70.     glVertex3f(pos.x-x.x-y.x, pos.y+-x.y-y.y, pos.z-x.z-y.z);
  71.  
  72.     glEnd();
  73.  
  74.     glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  75.     glDepthMask(GL_TRUE);
  76. }
  77.  
  78. bsp_object *hitmark::clone()
  79. {
  80.     hitmark *tmp=new hitmark;
  81.     *tmp=*this;
  82.     tmp->source=this;
  83.     return tmp;
  84. }
  85.  
  86. int hitmark::get_custom_param_desc(int i,param_desc *pd)
  87. {
  88.     if (pd!=0)
  89.     switch(i)
  90.     {
  91.         case 0:
  92.             pd->type='p';
  93.             pd->data=&texture;
  94.             strcpy(pd->name,"texture");
  95.             break;
  96.         case 1:
  97.             pd->type='f';
  98.             pd->data=&size;
  99.             strcpy(pd->name,"size");
  100.             break;
  101.         case 2:
  102.             pd->type='i';
  103.             pd->data=&fadetime;
  104.             strcpy(pd->name,"fadetime");
  105.             break;
  106.     }
  107.     return 3;
  108. }
  109.  
  110. int hitmark::message(vector& p,float rad,int msg,int param,void *data)
  111. {
  112.     if (msg==FLYOBJM_ILLUM)
  113.     {
  114.         float fac=(p-pos).length()/rad;
  115.         if (fac<1.0f)
  116.             dynlight+=*((vector *)data)*(1.0f-fac);
  117.     }
  118.  
  119.     return 1;
  120. }
  121.